//
//  TTNewStyleCell.m
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/24.
//  Copyright © 2016年 陶路路. All rights reserved.
//

#import "TTNewStyleCell.h"

@interface TTNewStyleCell ()

@property (nonatomic,strong) UIImageView * mainImage;

@property (nonatomic,strong) UIButton * mainButton;

@end

@implementation TTNewStyleCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.index = 0;
        
        [self setUpUI];
    }
    
    return self;
}

-(void)setIndex:(NSInteger)index{
    
    _index = index;
    
    self.mainImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%ld",index+1]];
    
    if (index == 3) {
        
        self.mainButton.hidden = NO;
        
        self.mainButton.transform = CGAffineTransformMakeScale(0, 0);
        
        [UIView animateWithDuration:2 delay:0.5 usingSpringWithDamping:0.6 initialSpringVelocity:0 options:0 animations:^{
            
            self.mainButton.transform = CGAffineTransformIdentity;
            
        } completion:^(BOOL finished) {
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"WelcomeViewController" object:nil];
        }];
      
    }else {
        
        self.mainButton.hidden = YES;
    }
}


-(void)setUpUI{
    
    [self addSubview:self.mainImage];
    [self.mainImage addSubview:self.mainButton];
    
    [self.mainImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self);
        
    }];
    
    [self.mainButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.centerX.equalTo(self);
        make.bottom.equalTo(self).offset(-100);
        make.height.equalTo(@36);
        make.width.equalTo(@100);
    }];
}


-(UIImageView *)mainImage{
    
    if (_mainImage == nil) {

        _mainImage = [[UIImageView alloc]init];
    }
    
    return _mainImage;
}

-(UIButton *)mainButton{
    
    if (_mainButton == nil) {
        
        _mainButton = [[UIButton alloc]init];
        
        [_mainButton setTitle:@"欢迎使用" forState:UIControlStateNormal];
        [_mainButton setBackgroundColor:[UIColor orangeColor]];
        _mainButton.layer.cornerRadius = 5;
        _mainButton.hidden = YES;
    }
    
    return _mainButton;
}
@end
